<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>props 初体验</title>
</head>

<body>
    <div id="root"> </div>

    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>

    <script type="text/babel">
        //外部数据, 可能是发送AJAX得到的结果值
        let obj = {
            name: '姚尊',
            age: 19, 
            gender: '男'
        };

        let obj2 = {
            name: '隋博', 
            age: 20, 
            gender: '男'
        }

        let obj3 = {
            name: '段佳敏', 
            age: 18, 
            gender: '女'
        }

        //类式组件
        class Person extends React.Component{
            //构造方法  规范写法
            constructor(props){
                super(props);
                //这里访问props属性  如果参数没有设置 props, 这下面无法访问this.props 的值
                console.log(this.props);
            }

            render(){
                // console.log(this.props);
                //解构赋值
                let {name, age, gender} = this.props;
                //返回虚拟 DOM 对象
                return <ul>
                            <li>姓名: {name}</li>
                            <li>年龄: {age}</li>
                            <li>性别: {gender}</li>
                        </ul>
            }
        }

        //渲染
        ReactDOM.render(<div>
                <Person name={obj.name} age={obj.age} gender={obj.gender}  />
                <Person {...obj2}  />
                <Person {...obj3}  />
            </div>
            , document.querySelector('#root'));
    </script>
</body>

</html>